<?php
apf_require_class("Bll_BLL");
class Bll_Attendance_Trip extends BLL{

    //写入出差信息
    public function insert_trip_record($array_record){
        //写入到leave_record
        $leave_id = $this->get_leaverecord_dao()->insert($array_record);
        if($leave_id){
            return $leave_id;
        }
        return false;
    }
    //写入详细信息
    public function insert_trip_detail($array_detail){
        //写入到trip_detail
        $detail = $this->get_tripdetails_dao()->insert($array_detail);
        if($detail){
            return $detail;
        }
        return FALSE;
    }
    //获取出差审批人,邮件地址
    public function get_dpt_info(){
        $this->session_act();
        $dpt_id = $_SESSION['department_id'];
        //取用户名和email
        $sql = "SELECT u.name,u.email,t.department_id,u.user_id from trip_manager t,user_info u where t.department_id= {$dpt_id} and u.user_id=t.user_id limit 1";
        $row = $this->get_leaverecord_dao()->find_by_sql($sql);
        if(!empty($row)){
            return $row[0];
        }
        return false;
    }
    public function get_dpt_by_id($dpt_id){
        $row = $this->get_tripmanager_dao()->find_by_id($dpt_id);
        return $row;
    }
    //获取主管id,org_relation 表
    public function get_sup_id(){
        $this->session_act();
        $user_id = $_SESSION['user_id'];
        $row = $this->get_orgrelation_dao()->find(array('user_id'=>$user_id));
        if(!empty($row)){
            $data = array();
            foreach($row as $v){
                $data[$v['level']] = $v['superior_id'];
            }
            return $data;
        }
        return false;
    }

    /**
     *请假记录写入到记录列表
     * @param array $date('uid'=>$date['uid'],'leave_id'=>$date['leave_id'],'status'=>$date['staus']);
     */
    public function replace_record($date){
        $sql = "REPlACE INTO audit_list(uid,leave_id,status) values('{$date['uid']}','{$date['leave_id']}','{$date['status']}')";
        return $this->get_orgrelation_dao()->execute($sql);
    }

    //get dao
    private function get_orgrelation_dao(){
        $dao = $this->get_dao('Dao_Attendance_OrgRelation');
        return $dao;
    }
    private function get_leaverecord_dao(){
        $dao = $this->get_dao('DAO_Attendance_LeaveRecord');
        return $dao;
    }
    private function get_tripdetails_dao(){
        return $this->get_dao('DAO_Attendance_TripDetail');
    }
    private function get_tripmanager_dao(){
        return $this->get_dao('DAO_Attendance_TripManager');
    }
}